package com.zzq.config.wx;

import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

@Component
public class WxPayConfigLoader {



    public  String loadPrivateKey(String privateKeyPath) throws IOException {
        File file = new File(privateKeyPath);
        InputStream inputStream=new FileInputStream(file);

        if (inputStream != null) {
            try (Scanner scanner = new Scanner(inputStream, StandardCharsets.UTF_8.name()).useDelimiter("\\A")) {
                return scanner.hasNext() ? scanner.next() : "";
            }
        } else {
            throw new IOException("Resource not found: " + privateKeyPath);
        }
    }

}
